<?php
/*******************************************************************************
 * Copyright(c) @2011 ANTERP SOLUTIONS. All rights reserved.
 *
 * Released under the terms of the GNU General Public License, GPL, 
 * as published by the Free Software Foundation, either version 3 
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 *
 * Authors		    tclim
 * Date Created     Mar 16, 2011 2:01:16 PM
 ******************************************************************************/
 require_once ('api/lib/nusoap.php');
 
 //Get the FrontAccounting Root Directory
 $arr_fa_dir = explode("/", $_SERVER["PHP_SELF"]);
 $_dir_fa_root = "/frontaccounting";
 
 //FrontAccounting Root Directory
 if (!empty($arr_fa_dir[1])) {
	$_dir_fa_root =  "/" . $arr_fa_dir[1];
 }
 
 $_http_protocol = "http://";

 if(!empty($_SERVER["HTTPS"])) {
	$_http_protocol = "https://";
 }

 $soapclient = new nusoap_client($_http_protocol . $_SERVER["HTTP_HOST"] . $_dir_fa_root . '/api/soap.php?wsdl',true);
 $soapclient->debug_flag=false;
 $err = $soapclient->getError();


 if (!file_exists('config_db.php')) {
	header("Location: ". "install/index.php");
 }
	
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Parameters Passing
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	 $_company = "ANTERP SOLUTIONS";// Default Company. It can be '0' or the actual company name that show on the FrontAccounting
	 $_uid= "demo1@anterp.com";  	// User Id for FrontAccounting
	 $_upswd = "password1"; 		// Password
	 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Method 1 -	Retrieve Debtors Master
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	 $_filter_by = "name LIKE '%'";
	 $_order_by = "name DESC";
	 $_page_index = 0; //Page index
	 $_total = 10; //Total Records
	  
	 $param =  array("company"=>$_company, 
	 				"user_id"=>$_uid,
					"password"=>$_upswd,
					"filter_by"=>$_filter_by,  
					"order_by"=>$_order_by,
					"page_index"=>$_page_index, 
					"total"=>$_total);
					
	 $antResults=$soapclient->call("get_debtors_masters",$param);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Method 2 - Retrieve Debtor Trans
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//	 $_filter_by = "";
//	 $_order_by = "";
//	 $_page_index = 0; //Page index
//	 $_total = 10; //Total Records
//	  
//	 $param =  array("company"=>$_company, 
//	 				"user_id"=>$_uid,
//					"password"=>$_upswd,
//					"filter_by"=>$_filter_by,  
//					"order_by"=>$_order_by,
//					"page_index"=>$_page_index, 
//					"total"=>$_total);
//					
//	 $antResults=$soapclient->call("get_debtor_trans",$param);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Method 3 - Create New Customer Account (Populate Data into Debtor Master, Branch, Personal and Contact)
// 			  Updating Customer Account use the same method but ONLY Debtor Master is updated
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//	$_company_name = "Tee Chert";	
//	$_short_name = strtolower(ereg_replace("[^A-Za-z0-9]`~!#'\"", "", str_replace(' ', '', $_company_name)));	
//
//	$_first_name = "Tee Chert";
//	$_last_name = "Lim";  
//	
// 	//Create Debtor Master 
//	 $param =  array("company"=> $_company,
//	 				"user_id"=> $_uid,
//					"password"=>$_upswd,
//					"id"=>"",  
//					"company_name"=>$_company_name,
//	 				"short_name"=>$_short_name,
//					"first_name"=>$_first_name,
//					"last_name"=>$_last_name,
//					"address"=>"J119, Jalan Perkasa 8, Taman Salak Selatan,\n 57100\nKuala Lumpur, Wilayah Persekutuan\nMalaysia",
//					"email"=>"tclim@anterp.com",  
//					"phone"=>"60377312918",
//					"mobile"=>"60122209266",
//					"fax"=>"",
//					"tax_group"=>"GST Tax",
//					"tax_id"=>"GST8888",
//					"area"=>"Asia",
//					"country_code"=>"MY",					
//					"currency_code"=>"MYR",
//					"customer_type"=>"Retail",  
//					"payment_terms"=>"Cash Only",
//					"credit_status_id"=>"1",
//					"notes"=>"Good Customer");
//					
//	 $antResults=$soapclient->call("create_debtors_masters",$param);
	 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Soap Debugging Code and Result
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	 
	 if ($soapclient->fault) {
          echo '<p><b>Fault: ';
          print_r($antResults);
          echo '</b></p>';
          echo '<p><b>Request: <br>';
          echo htmlspecialchars($soapclient->request, ENT_QUOTES) . '</b></p>';
          echo '<p><b>Response: <br>';
          echo htmlspecialchars($soapclient->response, ENT_QUOTES) . '</b></p>';
          echo '<p><b>Debug: <br>';
          echo htmlspecialchars($soapclient->debug_str, ENT_QUOTES) . '</b></p>';
     } else {
          $err = $soapclient->getError();
          if ($err) {
               echo '<p><b>Error: ' . $err . '</b></p>';
               echo '<p><b>Request: <br>';
               echo htmlspecialchars($soapclient->request, ENT_QUOTES) . '</b></p>';
               echo '<p><b>Response: <br>';
               echo htmlspecialchars($soapclient->response, ENT_QUOTES) . '</b></p>';
               echo '<p><b>Debug: <br>';
               echo htmlspecialchars($soapclient->debug_str, ENT_QUOTES) . '</b></p>';
          } else {
               print_r($antResults);
          }
     }
?>
